--[[

  提交状态报告后返回响应消息
--]]

function string.split(str, delimiter)
        if str==nil or str=='' or delimiter==nil then
                return nil
        end

    local result = {}
    for match in (str..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match)
    end
    return result
end

local array = {}
local index = 0

for i,v in ipairs(ARGV) do

    if (v ~= nil) then
    
        local args = string.split(v, ":")
     
	    local result = redis.call("zrem", KEYS[2], args[1])
	    
	    if (result == 1) then
	    
	        local ntfhvalue = redis.call("hmget", "SMNotifyHash:"..args[1], "ISMCacheKey", "IRptSnPart1", "IRptSnPart2", "IRptSnPart3", "ISendTimes", "INotifyType", "ILastSendTime")
	    
	        local cacheKey = ntfhvalue[1]
	        
	        if (cacheKey ~= nil and cacheKey ~= false) then
	        
	            redis.call("del", "SMNotifyHash:"..args[1])
	            
	            index = index + 1
	            
	            array[index] = ntfhvalue
	            
	        end
	    else
	        redis.call("zadd", KEYS[1], args[2], args[1])
	    end
    end
end

return array